package com.qyer.search.filter;

import com.qyer.search.Constants;
import com.qyer.search.model.Channel;
import com.qyer.search.model.SearchParameterOrigin;
import com.qyer.search.model.aggregation.ProductProject;
import com.qyer.search.model.lastminute.SKU;
import org.apache.commons.collections4.CollectionUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by tangzheng on 16/8/11.
 */
public class ChannelWithIDFilter extends AbstractIDFilter{

  public ChannelWithIDFilter(Object[] conditions) {
    super(conditions);
  }

  @Override public boolean isValid(ProductProject productProject, SearchParameterOrigin searchParameterOrigin) {

    Set<Integer> strings = new HashSet<>();
    int size = conditions.length;
    for(int i = 0; i < size; i++){
      strings.add(Constants.ChannelMap.get(String.valueOf(conditions[i]).trim()));
    }
    int id = productProject.getLid();
    List<Integer> channelList = productProject.getChannel();
    if (CollectionUtils.isNotEmpty(channelList)) {
      for (int channel : channelList) {
        strings.remove(channel);
      }
    }
    if(strings.size() == 0)
      return true;

    //logWarning(naSKU(id), searchParameterOrigin, null);
    return false;
  }
}
